﻿using PmSoft.ApplicationContext;
using PmSoft.Entity;
using Modules.System.User;
using System.Security;
using Modules.Commander;
using Modules.Project;
using System.Text;
using PmSoft;
using Modules.Device;
using Microsoft.Extensions.Primitives;
using Modules.Payroll;
using Pipelines.Sockets.Unofficial.Arenas;
using PmSoft.Utilities;
using Minio.DataModel;
using Modules.Person;
using Modules;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using Modules.Notify;
using Modules.BankSpecialAccount;
using ManagementApi.Mvc.ApplicationContexts;

namespace ManagementApi.Mvc.Authorization
{
    /// <summary>
    /// 默认权限认证
    /// </summary>
    public class DefaultAuthorizer : IAuthorizer
    {
        private readonly Dictionary<int, HashSet<string>> modulePermissions;
        private readonly ManagementApplicationContext applicationContext;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="applicationContext"></param>
        public DefaultAuthorizer(ManagementApplicationContext applicationContext)
        {
            this.modulePermissions = new Dictionary<int, HashSet<string>>();
            this.applicationContext = applicationContext;
        }

        /// <summary>
        /// 验证当前登录用户是否拥有权限
        /// </summary>
        /// <param name="permissionKeys"></param>
        /// <returns></returns>
        public bool Authorize(params string[] permissionKeys)
        {
            foreach (var permissionKey in permissionKeys)
            {
                if (Authorize(permissionKey))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// 验证当前登录用户是否拥有权限
        /// </summary>
        /// <param name="permissionKey"></param>
        /// <returns></returns>
        public bool Authorize(string permissionKey)
        {
            return Authorize(permissionKey, applicationContext.CurrentUser);
        }

        /// <summary>
        /// 验证当前登录用户是否拥有权限
        /// </summary>
        /// <param name="permissionKey"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Authorize(string permissionKey, IUser? user)
        {
            if (user == null)
                return false;

            if (string.IsNullOrWhiteSpace(permissionKey))
                return false;

            /*是否为系统用户*/
            if (user is not SysUser && user is not DeptUser)
                return false;

            /*超级管理员拥有所有权限*/
            //if (sysUser.IsSuperAdministrator())
            //	return true;

            SysUser? sysUser = applicationContext.GetService<UserService>().GetUser(user.Id);
            if (sysUser == null) return false;

            /*模块权限判断*/
            if (modulePermissions.ContainsKey(sysUser.UserId))
                return modulePermissions[sysUser.UserId].Contains(permissionKey, StringComparer.OrdinalIgnoreCase);
            var perKeys = sysUser.GetMenus().Where(m => !string.IsNullOrEmpty(m.Perm)).Select(m => m.Perm);
            if (perKeys == null || perKeys.Count() == 0)
                return false;

            HashSet<string> permissions = new HashSet<string>();
            foreach (var key in perKeys)
                permissions.Add(key);

            modulePermissions.Add(sysUser.UserId, permissions);
            return permissions.Contains(permissionKey, StringComparer.OrdinalIgnoreCase);
        }

        ///// <summary>
        ///// 验证当前登录用户是否有数据操作权限
        ///// </summary>
        ///// <returns></returns>
        //public bool DataAuthorize()
        //{
        //    HttpRequest? request = applicationContext.HttpContextAccessor?.HttpContext?.Request;
        //    if (request == null) return false;
        //    RouteValueDictionary routeDic = request.RouteValues;
        //    string action = routeDic["action"] as string ?? string.Empty;
        //    string controller = routeDic["controller"] as string ?? string.Empty;
        //    //TODO 优先做Manager的数据权限控制，然后再检查其他的
        //    var user = applicationContext.CurrentUser;
        //    if (user == null) return false;

        //    return DataAuthorizeManager(controller, action, request, user);
        //}

        ///// <summary>
        ///// 管理员数据权限验证
        ///// </summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="request"></param>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public bool DataAuthorizeManager(string controller, string action, HttpRequest request, IUser user)
        //{
        //    switch (controller)
        //    {
        //        case "CheckInDevice":
        //            //批量下发命令
        //            if (action == "IssueCommand")
        //            {
        //                var checkinDeviceService = applicationContext.GetService<CheckinDeviceService>();
        //                request.Query.TryGetValue("ids", out StringValues idsStr);
        //                var ids = idsStr.First() ?? string.Empty;
        //                var items = checkinDeviceService.GetProjectCheckinDevices(ValueUtility.ConvertToList<int>(ids));
        //                return items.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "SendCommand")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var memberId = request.RouteValues["memberId"] as int?;
        //                if (memberId == null) return false;
        //                var item = projectGroupMemberService.GetMember(memberId.Value);
        //                if (item == null) return false;
        //                return item.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "Common":
        //            if (action == "ProjectChanges")
        //            {
        //                var projects = applicationContext.GetService<ProjectService>().GetProjectInfosByManagerId(user.Id);
        //                var projectId = request.RouteValues["projectId"] as int?;
        //                if (projectId == null) return false;
        //                return projects.Any(s => s.ProjectId == projectId);
        //            }
        //            break;

        //        case "Payroll":
        //            var wagePayrollService = applicationContext.GetService<WagePayrollService>();
        //            if (action == "UpdateWagePayroll" || action == "Submit" || action == "Audit" || action == "AddWagePayrollDetails")
        //            {
        //                var id = request.RouteValues["id"] as int?;
        //                if (id == null) return false;
        //                var wagePayroll = wagePayrollService.Get(id.Value);
        //                if (wagePayroll == null) return false;
        //                return wagePayroll.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var wagePayrolls = wagePayrollService.GetWagePayrolls(ValueUtility.ConvertToList<int>(ids));
        //                return wagePayrolls.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "PersonBank":
        //            var personBankService = applicationContext.GetService<PersonBankService>();
        //            if (action == "UpdatePersonBank")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }
        //            break;

        //        case "PersonContract":
        //            var personCorpContractService = applicationContext.GetService<PersonCorpContractService>();
        //            if (action == "CreateContract")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }

        //            break;

        //        case "ProjectCompleted":
        //            var projectCompletedService = applicationContext.GetService<ProjectCompletedService>();
        //            if (action == "UpdateProjectCompleted")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var projectCompleteds = projectCompletedService.GetProjectCompleteds(ValueUtility.ConvertToList<int>(id));
        //                return projectCompleteds.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "DeleteProjectCompleted")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectCompleteds = projectCompletedService.GetProjectCompleteds(ValueUtility.ConvertToList<int>(ids));
        //                return projectCompleteds.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "Project":
        //            var projectService = applicationContext.GetService<ProjectService>();
        //            if (action == "UpdateProject" || action == "CreateUpdateProjectApply")
        //            {
        //                if (request.RouteValues["projectId"] is not string projectId) return false;
        //                var projects = projectService.GetProjectInfosByManagerId(user.Id);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "DeleteProject")
        //            {
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = projectService.GetProjectInfosByManagerId(user.Id);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            break;

        //        case "ProjectCorp":
        //            var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //            if (action == "UpdateProjectCorp")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "EnterArena" || action == "AppearStage")
        //            {
        //                if (request.RouteValues["projectCorpIds"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "ProjectGroup":
        //            var projectGroupService = applicationContext.GetService<ProjectGroupService>();

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectGroups = projectGroupService.GetProjectGroups(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroups.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "EditPersonGroupMember")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["newGroupId"]?.ToString(), out int newGroupId);
        //                _ = int.TryParse(form["oldGroupId"]?.ToString(), out int oldGroupId);
        //                _ = int.TryParse(form["personId"]?.ToString(), out int personId);

        //                var newGroup = projectGroupService.GetProjectGroup(newGroupId);
        //                var oldGroup = projectGroupService.GetProjectGroup(oldGroupId);
        //                if (newGroup == null) return false;
        //                if (oldGroup == null) return false;
        //                return newGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId && oldGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "AppearStage" || action == "EnterArena")
        //            {
        //                if (request.RouteValues["groupIds"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "InGroupMember" || action == "OutGroupMember")
        //            {
        //                if (request.RouteValues["memberId"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "UpdateProjectGroup")
        //            {
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var group = projectGroupService.GetProjectGroup(id);
        //                if (group == null) return false;
        //                return group.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectGuarantee":
        //            if (action == "UpdateProjectGuaranteePayment")
        //            {
        //                var projectGuaranteePaymentService = applicationContext.GetService<ProjectGuaranteePaymentService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["id"]?.ToString(), out int id);
        //                var payment = projectGuaranteePaymentService.GetProjectGuaranteePayment(id);
        //                if (payment == null) return false;
        //                return payment.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "DeleteProjectGuaranteePayment")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectGuaranteePaymentService = applicationContext.GetService<ProjectGuaranteePaymentService>();
        //                var payments = projectGuaranteePaymentService.GetProjectGuaranteePayments(ValueUtility.ConvertToList<int>(ids));
        //                return payments.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "ApplyProjectGuaranteeRefund")
        //            {
        //                var projectGuaranteePaymentService = applicationContext.GetService<ProjectGuaranteePaymentService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["guaranteePaymentId"]?.ToString(), out int id);
        //                var payment = projectGuaranteePaymentService.GetProjectGuaranteePayment(id);
        //                if (payment == null) return false;
        //                return payment.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectLockLog":
        //            if (action == "Update")
        //            {
        //                var projectLockLogService = applicationContext.GetService<ProjectLockLogService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectLockLog = projectLockLogService.Get(id);
        //                if (projectLockLog == null) return false;
        //                return projectLockLog.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectSpecialAccount":
        //            if (action == "Delete")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectSpecialAccounts = projectSpecialAccountService.GetProjectSpecialAccounts(ValueUtility.ConvertToList<int>(ids));
        //                return projectSpecialAccounts.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "UseEmployee":
        //            if (action == "EditPersonGroupMember")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "EditMemberLeader" || action == "Unbind" || action == "TransferManager")
        //            {
        //                if (request.RouteValues["memberId"] is not int id) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "WorkerNotify":
        //            if (action == "EditWorkerNotify")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                string id = form["id"]?.ToString() ?? string.Empty;
        //                var workerNotifyService = applicationContext.GetService<WorkerNotifyService>();
        //                var workerNotify = workerNotifyService.GetWorkerNotify(id);
        //                if (workerNotify == null) return false;
        //                return workerNotify.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "Delete")
        //            {
        //                var workerNotifyService = applicationContext.GetService<WorkerNotifyService>();
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var workerNotify = workerNotifyService.GetWorkerNotify(id);
        //                if (workerNotify == null) return false;
        //                return workerNotify.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //    return true;
        //}

        ///// <summary>
        ///// 企业用户数据权限验证
        ///// </summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="request"></param>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public bool DataAuthorizeCorp(string controller, string action, HttpRequest request, IUser user)
        //{
        //    switch (controller)
        //    {
        //        case "CheckInDevice":
        //            //批量下发命令
        //            if (action == "IssueCommand")
        //            {
        //                var checkinDeviceService = applicationContext.GetService<CheckinDeviceService>();
        //                request.Query.TryGetValue("ids", out StringValues idsStr);
        //                var ids = idsStr.First() ?? string.Empty;
        //                var items = checkinDeviceService.GetProjectCheckinDevices(ValueUtility.ConvertToList<int>(ids));
        //                return items.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "SendCommand")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var memberId = request.RouteValues["memberId"] as int?;
        //                if (memberId == null) return false;
        //                var item = projectGroupMemberService.GetMember(memberId.Value);
        //                if (item == null) return false;
        //                return item.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "Common":
        //            if (action == "ProjectChanges")
        //            {
        //                var projects = applicationContext.GetService<ProjectCorpService>().GetProjectCorpsByCorpId(user.Id).Where(i => i.Role != 项目参建单位类型.建设单位);
        //                var projectId = request.RouteValues["projectId"] as int?;
        //                if (projectId == null) return false;
        //                return projects.Any(s => s.ProjectId == projectId);
        //            }
        //            break;

        //        case "Payroll":
        //            var wagePayrollService = applicationContext.GetService<WagePayrollService>();
        //            if (action == "UpdateWagePayroll" || action == "Submit" || action == "Audit" || action == "AddWagePayrollDetails")
        //            {
        //                var id = request.RouteValues["id"] as int?;
        //                if (id == null) return false;
        //                var wagePayroll = wagePayrollService.Get(id.Value);
        //                if (wagePayroll == null) return false;
        //                return wagePayroll.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var wagePayrolls = wagePayrollService.GetWagePayrolls(ValueUtility.ConvertToList<int>(ids));
        //                return wagePayrolls.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "PersonBank":
        //            var personBankService = applicationContext.GetService<PersonBankService>();
        //            if (action == "UpdatePersonBank")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }
        //            break;

        //        case "PersonContract":
        //            var personCorpContractService = applicationContext.GetService<PersonCorpContractService>();
        //            if (action == "UpdateContract")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }

        //            break;

        //        case "Project":

        //            if (action == "UpdateProject" || action == "ResetManagerPassWord")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["projectId"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role != 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "DeleteProject")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role != 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "AuditProject")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role != 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "BindManager")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["projectId"]?.ToString(), out int projectId);
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role != 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId == projectId);
        //            }
        //            break;

        //        case "ProjectCorp":

        //            if (action == "UpdateProjectCorp")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "Delete")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["ids"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "ProjectGroup":
        //            var projectGroupService = applicationContext.GetService<ProjectGroupService>();

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectGroups = projectGroupService.GetProjectGroups(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroups.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "EditPersonGroupMember")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["newGroupId"]?.ToString(), out int newGroupId);
        //                _ = int.TryParse(form["oldGroupId"]?.ToString(), out int oldGroupId);
        //                _ = int.TryParse(form["personId"]?.ToString(), out int personId);

        //                var newGroup = projectGroupService.GetProjectGroup(newGroupId);
        //                var oldGroup = projectGroupService.GetProjectGroup(oldGroupId);
        //                if (newGroup == null) return false;
        //                if (oldGroup == null) return false;
        //                return newGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId && oldGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "AppearStage" || action == "EnterArena")
        //            {
        //                if (request.RouteValues["groupIds"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "InGroupMember" || action == "OutGroupMember")
        //            {
        //                if (request.RouteValues["memberId"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "UpdateProjectGroup")
        //            {
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var group = projectGroupService.GetProjectGroup(id);
        //                if (group == null) return false;
        //                return group.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectLockLog":
        //            if (action == "Update")
        //            {
        //                var projectLockLogService = applicationContext.GetService<ProjectLockLogService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectLockLog = projectLockLogService.Get(id);
        //                if (projectLockLog == null) return false;
        //                return projectLockLog.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectSpecialAccount":
        //            if (action == "Delete")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectSpecialAccounts = projectSpecialAccountService.GetProjectSpecialAccounts(ValueUtility.ConvertToList<int>(ids));
        //                return projectSpecialAccounts.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "AuditProjectSpecialAccount" || action == "UpdateAuditInfo")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["id"]?.ToString(), out int id);
        //                var account = projectSpecialAccountService.GetProjectSpecialAccount(id);
        //                return account?.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "UseEmployee":
        //            if (action == "EditPersonGroupMember")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "EditMemberLeader" || action == "Unbind" || action == "TransferManager")
        //            {
        //                if (request.RouteValues["memberId"] is not int id) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //    return true;
        //}

        ///// <summary>
        ///// 建设单位用户数据权限验证
        ///// </summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="request"></param>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public bool DataAuthorizeConstructor(string controller, string action, HttpRequest request, IUser user)
        //{
        //    switch (controller)
        //    {
        //        case "Commander":
        //            //批量下发命令
        //            if (action == "UpdateCommander")
        //            {
        //                var commanderService = applicationContext.GetService<CommanderService>();
        //                var commanderId = request.RouteValues["commanderId"] as int?;
        //                if (commanderId == null) return false;
        //                var commander = commanderService.GetCommanderInfo(commanderId.Value);
        //                if (commander == null) return false;
        //                return commander.ConstructorId == user.Id;
        //            }
        //            if (action == "UpdatePassword")
        //            {
        //                var commanderService = applicationContext.GetService<CommanderService>();
        //                var commanderId = request.RouteValues["commanderId"] as int?;
        //                if (commanderId == null) return false;
        //                var commander = commanderService.GetCommanderInfo(commanderId.Value);
        //                if (commander == null) return false;
        //                return commander.ConstructorId == user.Id;
        //            }
        //            if (action == "Delete")
        //            {
        //                var commanderService = applicationContext.GetService<CommanderService>();
        //                var commanderIds = request.RouteValues["commanderIds"] as string;
        //                var commanders = commanderService.GetCommanderInfos(ValueUtility.ConvertToList<int>(commanderIds ?? string.Empty));
        //                return commanders.All(i => i.ConstructorId == user.Id);
        //            }
        //            if (action == "SaveCommanderProject")
        //            {
        //                var commanderService = applicationContext.GetService<CommanderService>();
        //                var commanderId = request.RouteValues["commanderId"] as int?;
        //                if (commanderId == null) return false;
        //                var commander = commanderService.GetCommanderInfo(commanderId.Value);
        //                if (commander == null) return false;
        //                return commander.ConstructorId == user.Id;
        //            }
        //            break;

        //        case "Common":
        //            if (action == "ProjectChanges")
        //            {
        //                var projects = applicationContext.GetService<ProjectCorpService>().GetProjectCorpsByCorpId(user.Id).Where(i => i.Role == 项目参建单位类型.建设单位);
        //                var projectId = request.RouteValues["projectId"] as int?;
        //                if (projectId == null) return false;
        //                return projects.Any(s => s.ProjectId == projectId);
        //            }
        //            break;

        //        case "Payroll":
        //            var wagePayrollService = applicationContext.GetService<WagePayrollService>();
        //            if (action == "UpdateWagePayroll" || action == "Submit" || action == "Audit" || action == "AddWagePayrollDetails")
        //            {
        //                var id = request.RouteValues["id"] as int?;
        //                if (id == null) return false;
        //                var wagePayroll = wagePayrollService.Get(id.Value);
        //                if (wagePayroll == null) return false;
        //                return wagePayroll.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var wagePayrolls = wagePayrollService.GetWagePayrolls(ValueUtility.ConvertToList<int>(ids));
        //                return wagePayrolls.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "PersonBank":
        //            var personBankService = applicationContext.GetService<PersonBankService>();
        //            if (action == "UpdatePersonBank")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }
        //            break;

        //        case "PersonContract":
        //            var personCorpContractService = applicationContext.GetService<PersonCorpContractService>();
        //            if (action == "UpdateContract")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }

        //            break;

        //        case "Project":
        //            if (action == "UpdateProject" || action == "ResetManagerPassWord")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["projectId"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role == 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "DeleteProject")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role == 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "AuditProject")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role == 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "BindManager")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["projectId"]?.ToString(), out int projectId);
        //                var projects = projectCorpService.GetProjectCorpsByCorpId(user.Id).Where(i => i.Role == 项目参建单位类型.建设单位);
        //                return projects.Any(i => i.ProjectId == projectId);
        //            }
        //            break;

        //        case "ProjectCorp":
        //            if (action == "UpdateProjectCorp")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "Delete")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["ids"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "ProjectGroup":
        //            var projectGroupService = applicationContext.GetService<ProjectGroupService>();

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectGroups = projectGroupService.GetProjectGroups(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroups.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "EditPersonGroupMember")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["newGroupId"]?.ToString(), out int newGroupId);
        //                _ = int.TryParse(form["oldGroupId"]?.ToString(), out int oldGroupId);
        //                _ = int.TryParse(form["personId"]?.ToString(), out int personId);

        //                var newGroup = projectGroupService.GetProjectGroup(newGroupId);
        //                var oldGroup = projectGroupService.GetProjectGroup(oldGroupId);
        //                if (newGroup == null) return false;
        //                if (oldGroup == null) return false;
        //                return newGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId && oldGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "AppearStage" || action == "EnterArena")
        //            {
        //                if (request.RouteValues["groupIds"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "InGroupMember" || action == "OutGroupMember")
        //            {
        //                if (request.RouteValues["memberId"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "UpdateProjectGroup")
        //            {
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var group = projectGroupService.GetProjectGroup(id);
        //                if (group == null) return false;
        //                return group.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectLockLog":
        //            if (action == "Update")
        //            {
        //                var projectLockLogService = applicationContext.GetService<ProjectLockLogService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectLockLog = projectLockLogService.Get(id);
        //                if (projectLockLog == null) return false;
        //                return projectLockLog.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectSpecialAccount":
        //            if (action == "Delete")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectSpecialAccounts = projectSpecialAccountService.GetProjectSpecialAccounts(ValueUtility.ConvertToList<int>(ids));
        //                return projectSpecialAccounts.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "AuditProjectSpecialAccount" || action == "UpdateAuditInfo")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["id"]?.ToString(), out int id);
        //                var account = projectSpecialAccountService.GetProjectSpecialAccount(id);
        //                return account?.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "UseEmployee":
        //            if (action == "EditPersonGroupMember")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "EditMemberLeader" || action == "Unbind" || action == "TransferManager")
        //            {
        //                if (request.RouteValues["memberId"] is not int id) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //    return true;
        //}

        ///// <summary>
        ///// 指挥部用户数据权限验证
        ///// </summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="request"></param>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public bool DataAuthorizeCommander(string controller, string action, HttpRequest request, IUser user)
        //{
        //    switch (controller)
        //    {
        //        case "Common":
        //            if (action == "ProjectChanges")
        //            {
        //                var projects = applicationContext.GetService<CommanderProjectService>().GetCommanderProjectsByCommanderId(user.Id);
        //                var projectId = request.RouteValues["projectId"] as int?;
        //                if (projectId == null) return false;
        //                return projects.Any(s => s.ProjectId == projectId);
        //            }
        //            break;

        //        case "Payroll":
        //            var wagePayrollService = applicationContext.GetService<WagePayrollService>();
        //            if (action == "UpdateWagePayroll" || action == "Submit" || action == "Audit" || action == "AddWagePayrollDetails")
        //            {
        //                var id = request.RouteValues["id"] as int?;
        //                if (id == null) return false;
        //                var wagePayroll = wagePayrollService.Get(id.Value);
        //                if (wagePayroll == null) return false;
        //                return wagePayroll.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var wagePayrolls = wagePayrollService.GetWagePayrolls(ValueUtility.ConvertToList<int>(ids));
        //                return wagePayrolls.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "PersonBank":
        //            var personBankService = applicationContext.GetService<PersonBankService>();
        //            if (action == "UpdatePersonBank")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var personBanks = personBankService.GetPersonBanksByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return personBanks.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }
        //            break;

        //        case "PersonContract":
        //            var personCorpContractService = applicationContext.GetService<PersonCorpContractService>();
        //            if (action == "UpdateContract")
        //            {
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(id), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(id).Count;
        //            }

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var contracts = personCorpContractService.GetPersonCorpContractByIdsProjectId(ValueUtility.ConvertToList<int>(ids), applicationContext.CurrentProjectInfo.ProjectId);
        //                return contracts.Count() == ValueUtility.ConvertToList<int>(ids).Count;
        //            }

        //            break;

        //        case "Project":
        //            if (action == "UpdateProject" || action == "ResetManagerPassWord")
        //            {
        //                if (request.RouteValues["projectId"] is not string projectId) return false;
        //                var projects = applicationContext.GetService<CommanderProjectService>().GetCommanderProjectsByCommanderId(user.Id);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "DeleteProject")
        //            {
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = applicationContext.GetService<CommanderProjectService>().GetCommanderProjectsByCommanderId(user.Id);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "AuditProject")
        //            {
        //                if (request.RouteValues["id"] is not string projectId) return false;
        //                var projects = applicationContext.GetService<CommanderProjectService>().GetCommanderProjectsByCommanderId(user.Id);
        //                return projects.Any(i => i.ProjectId.ToString() == projectId);
        //            }
        //            if (action == "BindManager")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["projectId"]?.ToString(), out int projectId);
        //                var projects = applicationContext.GetService<CommanderProjectService>().GetCommanderProjectsByCommanderId(user.Id);
        //                return projects.Any(i => i.ProjectId == projectId);
        //            }
        //            break;

        //        case "ProjectCorp":
        //            if (action == "UpdateProjectCorp")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["id"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "Delete")
        //            {
        //                var projectCorpService = applicationContext.GetService<ProjectCorpService>();
        //                if (request.RouteValues["ids"] is not string id) return false;
        //                var projectCorps = projectCorpService.GetProjectCorps(ValueUtility.ConvertToList<int>(id));
        //                return projectCorps.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            break;

        //        case "ProjectGroup":
        //            var projectGroupService = applicationContext.GetService<ProjectGroupService>();

        //            if (action == "Delete")
        //            {
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectGroups = projectGroupService.GetProjectGroups(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroups.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "EditPersonGroupMember")
        //            {
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["newGroupId"]?.ToString(), out int newGroupId);
        //                _ = int.TryParse(form["oldGroupId"]?.ToString(), out int oldGroupId);
        //                _ = int.TryParse(form["personId"]?.ToString(), out int personId);

        //                var newGroup = projectGroupService.GetProjectGroup(newGroupId);
        //                var oldGroup = projectGroupService.GetProjectGroup(oldGroupId);
        //                if (newGroup == null) return false;
        //                if (oldGroup == null) return false;
        //                return newGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId && oldGroup.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "AppearStage" || action == "EnterArena")
        //            {
        //                if (request.RouteValues["groupIds"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "InGroupMember" || action == "OutGroupMember")
        //            {
        //                if (request.RouteValues["memberId"] is not string ids) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMembers = projectGroupMemberService.GetProjectGroupMembersByGroupIds(ValueUtility.ConvertToList<int>(ids));
        //                return projectGroupMembers.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "UpdateProjectGroup")
        //            {
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var group = projectGroupService.GetProjectGroup(id);
        //                if (group == null) return false;
        //                return group.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectLockLog":
        //            if (action == "Update")
        //            {
        //                var projectLockLogService = applicationContext.GetService<ProjectLockLogService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectLockLog = projectLockLogService.Get(id);
        //                if (projectLockLog == null) return false;
        //                return projectLockLog.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "ProjectSpecialAccount":
        //            if (action == "Delete")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                if (request.RouteValues["ids"] is not string ids) return false;
        //                var projectSpecialAccounts = projectSpecialAccountService.GetProjectSpecialAccounts(ValueUtility.ConvertToList<int>(ids));
        //                return projectSpecialAccounts.All(i => i.ProjectId == applicationContext.CurrentProjectInfo.ProjectId);
        //            }
        //            if (action == "AuditProjectSpecialAccount" || action == "UpdateAuditInfo")
        //            {
        //                var projectSpecialAccountService = applicationContext.GetService<BankSpecialAccountService>();
        //                Stream straem = request.Body;
        //                Encoding encoding = Encoding.UTF8;
        //                string body = string.Empty;
        //                using StreamReader reader = new(straem, encoding);
        //                JObject form = JObject.Parse(reader.ReadToEndAsync().Result);
        //                _ = int.TryParse(form["id"]?.ToString(), out int id);
        //                var account = projectSpecialAccountService.GetProjectSpecialAccount(id);
        //                return account?.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;

        //        case "UseEmployee":
        //            if (action == "EditPersonGroupMember")
        //            {
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                if (request.RouteValues["id"] is not int id) return false;
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            if (action == "EditMemberLeader" || action == "Unbind" || action == "TransferManager")
        //            {
        //                if (request.RouteValues["memberId"] is not int id) return false;
        //                var projectGroupMemberService = applicationContext.GetService<ProjectGroupMemberService>();
        //                var projectGroupMember = projectGroupMemberService.GetMember(id);
        //                if (projectGroupMember == null) return false;
        //                return projectGroupMember.ProjectId == applicationContext.CurrentProjectInfo.ProjectId;
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //    return true;
        //}

        ///// <summary>
        ///// 主管单位数据权限限制
        ///// </summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="request"></param>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public bool DataAuthorizeAdmin(string controller, string action, HttpRequest request, IUser user)
        //{
        //    return true;
        //}
    }
}